package PassengerVehicle

import java.io.{FileWriter, PrintWriter}
import java.sql.ResultSet


/**
  * 为计算省内省外客流量准备数据
  */
object convertSql {

  /*def main(args: Array[String]): Unit = {

    val month = 4
    val monthexp = s"FCRQSJ >= '2019-0${month}-01 00:00:00' AND FCRQSJ < '2019-0${month + 1}-01 00:00:00'"


    val writer = new FileWriter("/Users/chuxiaowei/IdeaProjects/两客一货/dataprocess/src/main/resources/base.csv")
    val printer = new PrintWriter(writer)
    printer.println("ID,XL,DDZ,FCRQSJ,SCKCCPHM")

    val connection = MysqlUtils.getConnection
    val countSet = MysqlUtils.select("select count(ID) from zhjg_jsy_ticket_smz_curmonth where " + monthexp)
    countSet.next()
    val l = countSet.getInt(1)
    val c = l / 10000 + 1
    println("count:" + c)

    var resultSet: ResultSet = null;
    for (i <- 0 until c) {
      resultSet = MysqlUtils.select("select ID, XL, DDZ, SCKCCPHM ,DATE_FORMAT(FCRQSJ, '%Y-%m-%d %H:%i') as FCRQSJ from zhjg_jsy_ticket_smz_curmonth where "+ monthexp +" limit " + i*10000 + ",10000")
      while (resultSet.next()) {
        val id = resultSet.getString("ID")
        val xl = resultSet.getString("XL")
        val ddz = resultSet.getString("DDZ")
        val fcrqsj = resultSet.getString("FCRQSJ")
        val sckccphm = resultSet.getString("SCKCCPHM")

        printer.println(id + "," + xl + "," + ddz +"," + fcrqsj + "," + sckccphm)
      }
      println("complete ---------- "  + (i+1))
    }

    printer.close()
    writer.close()
    resultSet.close()
    connection.close()


  }*/

}
